from google.appengine.api import users
from google.appengine.ext import webapp

from ..scheduler import Notification

class AddItem(webapp.RequestHandler):
    def get(self):
        self.post()

    def post(self):
        n = Notification(
            user=users.get_current_user(),
            description=self.request.get('description'),
            years=[int(x) for x in self.request.get('years').split()],
            months=[int(x) for x in self.request.get('months').split()],
            days=[int(x) for x in self.request.get('days').split()],
            hours=[int(x) for x in self.request.get('hours').split()],
            minutes=[int(x) for x in self.request.get('minutes').split()])

        n.put()

        scheduler.add_item(n)

        self.redirect('/')
